package zdream.pmfield.stage.effect;

import java.util.function.Function;

import zdream.pmfield.stage.action.AttackAction;
import zdream.pmfield.stage.action.MovementAction;
import zdream.pmfield.stage.director.HookStore;
import zdream.pmfield.stage.director.HookType;
import zdream.pmfield.stage.director.Hooks;
import zdream.pmfield.stage.object.FoeActor;

import static zdream.pmfield.data.foe.MoveAdditionalEffects.E_MOVE_TO;

/**
 * @author Zdream
 * @date 2023-11-30
 * @since 0.0.1
 */
public class MoveToEffect extends AbstractEffect {
	public MoveToEffect() {
		super(E_MOVE_TO);
	}

	@Override
	public void init(Function<HookType, HookStore.HookHandlerBuilder> onHook) {
		onHook.apply(HookType.AFTER_EXECUTE_ATTACK)
				.handle(this::createMovement)
				.buildAndSave();
	}

	private void createMovement(Hooks.HookContext rawContext) {
		final Hooks.AttackHookContext hooks = rawContext.as();
		final FoeActor foe = hooks.attackContext.attacker;

		MovementAction action = new MovementAction();
		action.target = foe;
		action.from = foe.seat;
		action.to = hooks.attackContext.action.targetSeat;
		foe.putActionNow(action);
	}
}
